package jhunter.common.groovy;

import groovy.lang.GroovyClassLoader;
import jhunter.common.exception.BaseException;

import org.codehaus.groovy.control.CompilationFailedException;
import org.springframework.util.ClassUtils;

public class GroovyLoader {

	private static GroovyClassLoader groovyClassLoader = new GroovyClassLoader(ClassUtils.getDefaultClassLoader());

	public static <T> Class<T> loadClass(String clazzString) {
		try {
			@SuppressWarnings("unchecked")
			Class<T> clazz = groovyClassLoader.parseClass(clazzString);
			return clazz;
		} catch (CompilationFailedException e) {
			e.printStackTrace();
			throw new BaseException(e);
		}
	}

}
